package com.lyf.baoxian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.lyf.baoxian.R;
import com.lyf.baoxian.bean.CustomerBaoDan;
import com.lyf.baoxian.bean.HistoryCustomer;

import java.util.List;

/**
 * Created by 刘亚飞 on 2017/1/9.
 */

public class HistoryAdapter extends BaseAdapter {
    private List<HistoryCustomer> datas;
    private Context context;

    public HistoryAdapter(Context context) {
        this.context = context;
    }

    public void setDatas(List<HistoryCustomer> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        VieHolder holder;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_history,null);
            holder = new VieHolder();
            holder.ivTX = (ImageView) view.findViewById(R.id.iv_history);
            holder.tvName = (TextView) view.findViewById(R.id.nameHistory);
            holder.tvID = (TextView) view.findViewById(R.id.tvId);
            holder.tvTC = (TextView) view.findViewById(R.id.tvTC);
            view.setTag(holder);
        }else {
            holder = (VieHolder) view.getTag();
        }

        HistoryCustomer historyCustomer = datas.get(i);
        holder.ivTX.setImageResource(historyCustomer.getImageView());
        holder.tvName.setText(historyCustomer.getName());
        holder.tvID.setText(historyCustomer.getPersonId());
        holder.tvTC.setText(historyCustomer.getTaocan());
        return view;
    }

    class VieHolder {
        ImageView ivTX; //头像
        TextView tvName; //姓名
        TextView tvID;  //身份证号码
        TextView tvTC;  //套餐
    }
}
